<?php
declare(strict_types=1);

namespace App\Utils\Other\Payment\Neopay;

/**
 * 支付单报关
 * @package App\Utils\Other\Payment\Neopay
 */
Class Declares extends App {

    /**
     * 推送支付单
     * @param array $params
     * @return array
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function push(array $params): array
    {
        $this->setPath('api/transactions/commit_custom/create');

        [$accessToken,] = $this->accessToken();
        $params['preEbpCode'] = $this->getConfig('pre_ebp_code');
        $orderList = json_encode([$params], JSON_UNESCAPED_UNICODE);
        $params['encryptInfo'] = [
            'loginId' => $this->getConfig('login_id'),
            'accessToken' => $accessToken,
            'orderList' => $orderList
        ];

        return $this->request($params);
    }

    /**
     * 查询支付单
     * @param array $params
     * @return array
     */
    public function query(array $params): array
    {
        $this->setPath('api/transactions/commit_custom/search');

        [$accessToken,] = $this->accessToken();
        $params['encryptInfo'] = [
            'loginId' => $this->getConfig('login_id'),
            'accessToken' => $accessToken
        ];

        return $this->request($params);
    }
}